class code4 {
    public int reverse(int x) {

        try {
            int falg = 1;
            //处理-号
            if(x<0) {
                x = -x;
                falg = -1;
            }
            //转为string
            String s = String.valueOf(x);

            //翻转
            StringBuffer ss = new StringBuffer(s);
            String s1 = ss.reverse().toString();

            //转为int
            int ret = Integer.parseInt(s1);

            ret *=falg;

            return ret;
        } catch(Exception e) {
            //判断是否在范围内
            return 0;
        }

    }
}